package com.hualan.sfzy.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.mapper.FmMapper;
import com.hualan.sfzy.model.dto.FmDto;
import com.hualan.sfzy.model.entity.Article;
import com.hualan.sfzy.model.entity.Fm;
import com.hualan.sfzy.model.vo.FmQuery;
import com.hualan.sfzy.service.FmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * FM服务实现类
 */
@Service
public class FmServiceImpl implements FmService {
    @Autowired
    private FmMapper fmMapper;

    @Override
    public int add(Fm entity) {
        return fmMapper.insert(entity);
    }

    @Override
    public int edit(Fm entity) {
        return fmMapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return fmMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return fmMapper.deleteBatch(ids);
    }

    @Override
    public List<Fm> find() {
        return fmMapper.select(new Fm());
    }

    @Override
    public Map<String, Object> findFmPage(Integer pageNum, Integer pageSize, FmQuery entity) {
        PageHelper.startPage(pageNum, pageSize);
        List<FmDto> list = fmMapper.select(entity);
        PageInfo<FmDto> pageInfo = new PageInfo<>(list);
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put(CommonConstant.PAGE_LIST, list);
        pageMap.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        pageMap.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return pageMap;
    }
    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Fm entity) {
        // 可以空实现（如果确认不会被调用），或抛出不支持的异常
        throw new UnsupportedOperationException("此方法不支持，请使用findArticlePage");

    }

    @Override
    public Fm findById(Integer id) {
        return fmMapper.selectById(id);
    }
    
    @Override
    public List<FmDto> findAll() {
        return fmMapper.selectAll();
    }
}